package com.idp.biz.bppost.service.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.common.model.PageModel;
import com.common.utils.ResourceUtil;
import com.idp.biz.bppost.service.BpPostService;
import com.idp.biz.bppost.dao.BpPostDao;
import com.idp.biz.bppost.entity.BpPost;

/**
 * 帖子管理service实现类
 * 
 * @author Stone 2019-06-29
 *
 */
@Service("bpPostService")
public class BpPostServiceImpl implements BpPostService {

	@Autowired
	private BpPostDao bpPostDao;
	
	@Override
	public PageModel<BpPost> findByPage(BpPost bpPost, PageModel<BpPost> page) {
		PageHelper.offsetPage(page.getStart(), page.getLength());
		page.initData(bpPostDao.findByPage(bpPost));
		return page;
	}
	
	@Override
	public List<BpPost> findBySearch(BpPost bpPost) {
		return bpPostDao.find(bpPost);
	}
	
	@Override
	public BpPost getById(String id) {
		return bpPostDao.getById(id);
	}
	@Override
	public BpPost getDataById(String postId) {
		return bpPostDao.getDataById(postId);
	}

	@Override
	public void add(BpPost bpPost) {
		bpPost.setId(ResourceUtil.getUUID());
		bpPostDao.add(bpPost);
	}
	
	@Override
	public void update(BpPost bpPost) {
//		bpPostDao.update(bpPost);
		bpPostDao.updateNotNull(bpPost);
	}

	@Override
	public void delete(String ids) {
		List<String> idList = Arrays.asList(ids.split(","));
		bpPostDao.batchDelete(idList);
	}
 	
}